
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Go 语言数据类型 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../part6/" />
    
    
    <link rel="prev" href="../part4/" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../part1/">
            
                <a href="../part1/">
            
                    
                    Go 语言简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../part2/">
            
                <a href="../part2/">
            
                    
                    Go 语言环境安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../part3/">
            
                <a href="../part3/">
            
                    
                    Go 语言结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../part4/">
            
                <a href="../part4/">
            
                    
                    Go 语言基础语法
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6" data-path="./">
            
                <a href="./">
            
                    
                    Go 语言数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../part6/">
            
                <a href="../part6/">
            
                    
                    Go 语言变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../part7/">
            
                <a href="../part7/">
            
                    
                    Go 语言常量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../part8/">
            
                <a href="../part8/">
            
                    
                    Go 语言运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../part9/">
            
                <a href="../part9/">
            
                    
                    Go 语言条件语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../part10/">
            
                <a href="../part10/">
            
                    
                    Go 语言循环语句
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../part11/">
            
                <a href="../part11/">
            
                    
                    Go 语言函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../part12/">
            
                <a href="../part12/">
            
                    
                    Go 语言数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../part13/">
            
                <a href="../part13/">
            
                    
                    Go 语言指针
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../part14/">
            
                <a href="../part14/">
            
                    
                    Go 语言结构体
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../part15/">
            
                <a href="../part15/">
            
                    
                    Go 语言切片(Slice)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../part16/">
            
                <a href="../part16/">
            
                    
                    Go 语言范围(Range)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="../part17/">
            
                <a href="../part17/">
            
                    
                    Go 语言Map(集合)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="../part18/">
            
                <a href="../part18/">
            
                    
                    Go 语言递归函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.20" data-path="../part19/">
            
                <a href="../part19/">
            
                    
                    Go 语言类型转换
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.21" data-path="../part20/">
            
                <a href="../part20/">
            
                    
                    Go 语言接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.22" data-path="../part21/">
            
                <a href="../part21/">
            
                    
                    Go 错误处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.23" data-path="../part22/">
            
                <a href="../part22/">
            
                    
                    Go 并发
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Go 语言数据类型</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="go-&#x8BED;&#x8A00;&#x6570;&#x636E;&#x7C7B;&#x578B;">Go &#x8BED;&#x8A00;&#x6570;&#x636E;&#x7C7B;&#x578B;</h1>
<p style="text-indent:2em">
&#x5728; Go &#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7528;&#x4E8E;&#x58F0;&#x660E;&#x51FD;&#x6570;&#x548C;&#x53D8;&#x91CF;&#x3002;
</p>

<p style="text-indent:2em">
&#x6570;&#x636E;&#x7C7B;&#x578B;&#x7684;&#x51FA;&#x73B0;&#x662F;&#x4E3A;&#x4E86;&#x628A;&#x6570;&#x636E;&#x5206;&#x6210;&#x6240;&#x9700;&#x5185;&#x5B58;&#x5927;&#x5C0F;&#x4E0D;&#x540C;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x7F16;&#x7A0B;&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x7528;&#x5927;&#x6570;&#x636E;&#x7684;&#x65F6;&#x5019;&#x624D;&#x9700;&#x8981;&#x7533;&#x8BF7;&#x5927;&#x5185;&#x5B58;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5145;&#x5206;&#x5229;&#x7528;&#x5185;&#x5B58;&#x3002;
</p>

<p>Go &#x8BED;&#x8A00;&#x6309;&#x7C7B;&#x522B;&#x6709;&#x4EE5;&#x4E0B;&#x51E0;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF1A;</p>
<ol>
<li><strong>&#x5E03;&#x5C14;&#x578B;</strong><ul>
<li>&#x5E03;&#x5C14;&#x578B;&#x7684;&#x503C;&#x53EA;&#x53EF;&#x4EE5;&#x662F;&#x5E38;&#x91CF; true &#x6216;&#x8005; false&#x3002;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x4F8B;&#x5B50;&#xFF1A;var b bool = true</li>
</ul>
</li>
<li><strong>&#x6570;&#x5B57;&#x7C7B;&#x578B;</strong><ul>
<li>&#x6574;&#x578B; int &#x548C;&#x6D6E;&#x70B9;&#x578B; float32&#x3001;float64&#xFF0C;Go &#x8BED;&#x8A00;&#x652F;&#x6301;&#x6574;&#x578B;&#x548C;&#x6D6E;&#x70B9;&#x578B;&#x6570;&#x5B57;&#xFF0C;&#x5E76;&#x4E14;&#x652F;&#x6301;&#x590D;&#x6570;&#xFF0C;&#x5176;&#x4E2D;&#x4F4D;&#x7684;&#x8FD0;&#x7B97;&#x91C7;&#x7528;&#x8865;&#x7801;&#x3002;</li>
</ul>
</li>
<li><strong>&#x5B57;&#x7B26;&#x4E32;&#x7C7B;&#x578B;</strong><ul>
<li>&#x5B57;&#x7B26;&#x4E32;&#x5C31;&#x662F;&#x4E00;&#x4E32;&#x56FA;&#x5B9A;&#x957F;&#x5EA6;&#x7684;&#x5B57;&#x7B26;&#x8FDE;&#x63A5;&#x8D77;&#x6765;&#x7684;&#x5B57;&#x7B26;&#x5E8F;&#x5217;&#x3002;Go &#x7684;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x7531;&#x5355;&#x4E2A;&#x5B57;&#x8282;&#x8FDE;&#x63A5;&#x8D77;&#x6765;&#x7684;&#x3002;Go &#x8BED;&#x8A00;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5B57;&#x8282;&#x4F7F;&#x7528; UTF-8 &#x7F16;&#x7801;&#x6807;&#x8BC6; Unicode &#x6587;&#x672C;&#x3002;</li>
</ul>
</li>
<li><strong>&#x6D3E;&#x751F;&#x7C7B;&#x578B;</strong><ul>
<li>(a) &#x6307;&#x9488;&#x7C7B;&#x578B;&#xFF08;Pointer&#xFF09;</li>
<li>(b) &#x6570;&#x7EC4;&#x7C7B;&#x578B;</li>
<li>(c) &#x7ED3;&#x6784;&#x5316;&#x7C7B;&#x578B;(struct)</li>
<li>(d) Channel &#x7C7B;&#x578B;</li>
<li>(e) &#x51FD;&#x6570;&#x7C7B;&#x578B;</li>
<li>(f) &#x5207;&#x7247;&#x7C7B;&#x578B;</li>
<li>(g) &#x63A5;&#x53E3;&#x7C7B;&#x578B;&#xFF08;interface&#xFF09;</li>
<li>(h) Map &#x7C7B;&#x578B;</li>
</ul>
</li>
</ol>
<hr>
<h2 id="&#x6570;&#x5B57;&#x7C7B;&#x578B;">&#x6570;&#x5B57;&#x7C7B;&#x578B;</h2>
<p>Go &#x4E5F;&#x6709;&#x57FA;&#x4E8E;&#x67B6;&#x6784;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;<code>int</code>&#x3001;<code>uint</code> &#x548C; <code>uintptr</code>&#x3002;</p>
<ol>
<li><p><strong>uint8</strong></p>
<ul>
<li>&#x65E0;&#x7B26;&#x53F7; 8 &#x4F4D;&#x6574;&#x578B; (0 &#x5230; 255)</li>
</ul>
</li>
<li><p><strong>uint16</strong></p>
<ul>
<li>&#x65E0;&#x7B26;&#x53F7; 16 &#x4F4D;&#x6574;&#x578B; (0 &#x5230; 65535)</li>
</ul>
</li>
<li><p><strong>uint32</strong></p>
<ul>
<li>&#x65E0;&#x7B26;&#x53F7; 32 &#x4F4D;&#x6574;&#x578B; (0 &#x5230; 4294967295)</li>
</ul>
</li>
<li><p><strong>uint64</strong></p>
<ul>
<li>&#x65E0;&#x7B26;&#x53F7; 64 &#x4F4D;&#x6574;&#x578B; (0 &#x5230; 18446744073709551615)</li>
</ul>
</li>
<li><p><strong>int8</strong></p>
<ul>
<li>&#x6709;&#x7B26;&#x53F7; 8 &#x4F4D;&#x6574;&#x578B; (-128 &#x5230; 127)</li>
</ul>
</li>
<li><p><strong>int16</strong></p>
<ul>
<li>&#x6709;&#x7B26;&#x53F7; 16 &#x4F4D;&#x6574;&#x578B; (-32768 &#x5230; 32767)</li>
</ul>
</li>
<li><p><strong>int32</strong></p>
<ul>
<li>&#x6709;&#x7B26;&#x53F7; 32 &#x4F4D;&#x6574;&#x578B; (-2147483648 &#x5230; 2147483647)</li>
</ul>
</li>
<li><p><strong>int64</strong></p>
<ul>
<li>&#x6709;&#x7B26;&#x53F7; 64 &#x4F4D;&#x6574;&#x578B; (-9223372036854775808 &#x5230; 9223372036854775807)</li>
</ul>
</li>
</ol>
<h2 id="&#x6D6E;&#x70B9;&#x578B;">&#x6D6E;&#x70B9;&#x578B;</h2>
<ol>
<li><p><strong>float32</strong></p>
<ul>
<li>IEEE-754 32&#x4F4D;&#x6D6E;&#x70B9;&#x578B;&#x6570;</li>
</ul>
</li>
<li><p><strong>float64</strong></p>
<ul>
<li>IEEE-754 64&#x4F4D;&#x6D6E;&#x70B9;&#x578B;&#x6570;</li>
</ul>
</li>
<li><p><strong>complex64</strong></p>
<ul>
<li>32 &#x4F4D;&#x5B9E;&#x6570;&#x548C;&#x865A;&#x6570;</li>
</ul>
</li>
<li><p><strong>complex128</strong></p>
<ul>
<li>64 &#x4F4D;&#x5B9E;&#x6570;&#x548C;&#x865A;&#x6570;</li>
</ul>
</li>
</ol>
<h2 id="&#x5176;&#x4ED6;&#x6570;&#x5B57;&#x7C7B;&#x578B;">&#x5176;&#x4ED6;&#x6570;&#x5B57;&#x7C7B;&#x578B;</h2>
<p>&#x4EE5;&#x4E0B;&#x5217;&#x51FA;&#x4E86;&#x5176;&#x4ED6;&#x66F4;&#x591A;&#x7684;&#x6570;&#x5B57;&#x7C7B;&#x578B;&#xFF1A;</p>
<ol>
<li><p><strong>byte</strong></p>
<ul>
<li>&#x7C7B;&#x4F3C; uint8</li>
</ul>
</li>
<li><p><strong>rune</strong></p>
<ul>
<li>&#x7C7B;&#x4F3C; int32</li>
</ul>
</li>
<li><p><strong>uint</strong></p>
<ul>
<li>&#x7C7B;&#x4F3C; 32 &#x6216; 64 &#x4F4D;</li>
</ul>
</li>
<li><p><strong>int</strong></p>
<ul>
<li>&#x4E0E; uint &#x4E00;&#x6837;&#x5927;&#x5C0F;</li>
</ul>
</li>
<li><p><strong>uintptr</strong></p>
<ul>
<li>&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x578B;&#xFF0C;&#x7528;&#x4E8E;&#x5B58;&#x653E;&#x4E00;&#x4E2A;&#x6307;&#x9488;</li>
</ul>
</li>
</ol>
<hr>
<h2 id="ps">PS</h2>
<p>&#x5B57;&#x7B26;&#x4E32;&#x53BB;&#x9664;&#x7A7A;&#x683C;&#x548C;&#x6362;&#x884C;&#x7B26;</p>
<pre><code class="lang-go"><span class="hljs-keyword">package</span> main  

<span class="hljs-keyword">import</span> (  
    <span class="hljs-string">&quot;fmt&quot;</span>  
    <span class="hljs-string">&quot;strings&quot;</span>  
)  

<span class="hljs-keyword">func</span> main() {  
    str := <span class="hljs-string">&quot;&#x8FD9;&#x91CC;&#x662F; www\n.baidu\n.com&quot;</span>  
    fmt.Println(<span class="hljs-string">&quot;-------- &#x539F;&#x5B57;&#x7B26;&#x4E32; ----------&quot;</span>)  
    fmt.Println(str)  
    <span class="hljs-comment">// &#x53BB;&#x9664;&#x7A7A;&#x683C;  </span>
    str = strings.Replace(str, <span class="hljs-string">&quot; &quot;</span>, <span class="hljs-string">&quot;&quot;</span>, <span class="hljs-number">-1</span>)  
    <span class="hljs-comment">// &#x53BB;&#x9664;&#x6362;&#x884C;&#x7B26;  </span>
    str = strings.Replace(str, <span class="hljs-string">&quot;\n&quot;</span>, <span class="hljs-string">&quot;&quot;</span>, <span class="hljs-number">-1</span>)  
    fmt.Println(<span class="hljs-string">&quot;-------- &#x53BB;&#x9664;&#x7A7A;&#x683C;&#x4E0E;&#x6362;&#x884C;&#x540E; ----------&quot;</span>)  
    fmt.Println(str)  
}
</code></pre>
<p>&#x8F93;&#x51FA;&#x7ED3;&#x679C;&#x4E3A;&#xFF1A;</p>
<pre><code class="lang-sh">-------- &#x539F;&#x5B57;&#x7B26;&#x4E32; ----------
&#x8FD9;&#x91CC;&#x662F; www
.baidu
.com
-------- &#x53BB;&#x9664;&#x7A7A;&#x683C;&#x4E0E;&#x6362;&#x884C;&#x540E; ----------
&#x8FD9;&#x91CC;&#x662F;www.baidu.com
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../part4/" class="navigation navigation-prev " aria-label="Previous page: Go 语言基础语法">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../part6/" class="navigation navigation-next " aria-label="Next page: Go 语言变量">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Go 语言数据类型","level":"1.6","depth":1,"next":{"title":"Go 语言变量","level":"1.7","depth":1,"path":"part6/README.md","ref":"part6/README.md","articles":[]},"previous":{"title":"Go 语言基础语法","level":"1.5","depth":1,"path":"part4/README.md","ref":"part4/README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"part5/README.md","mtime":"2021-01-19T06:08:29.031Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-01-21T06:29:04.898Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

